package com.test.util;

import java.util.List;

public class Page {
	private int totalCount;// 总行数
	
	private int pageCount;// 总页数
	private int pageSize;// 每页记录数
	private int pageNo;// 当前页
	private List result;// 记录

	
	public Page(int pageSize) {
		super();
		if (pageSize < 1) {this.pageSize = 1;}
		else {this.pageSize = pageSize;}
		this.pageNo = 1;
	}

	public int getTotalCount() {
		return totalCount;
	}
	
	/**
	 * 设置总记录数
	 * 计算总页数
	 * 如果当前页大于总页数,则把当前页设为最后一页
	 * @param totalCount
	 */
	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
		
		if (pageNo < 1) {
			pageNo = 1;
		}
		pageCount = totalCount / pageSize;
		if (totalCount % pageSize > 0) {
			pageCount++;
		}
		if (pageNo > pageCount) {
			pageNo = pageCount;
		}
	}
	//当前记录
	public int getStart() {
		return (this.pageNo-1) * this.pageSize;
	}
	//终止记录
	public int getEnd() {
		return this.pageNo * this.pageSize - 1;
	}
	
	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * 设置当前页
	 * @param startPage 小于1则默认为1
	 */
	public void setStartPage(int startPage) {
		if (startPage < 1) {
			this.pageNo = 1;
		} else {
			this.pageNo = startPage;
		}
	}

	public List getResult() {
		return result;
	}

	public void setResult(List result) {
		this.result = result;
	}

}
